﻿SSVC.Utils.Page.IncludeFile("../styles/FeedToolbar.css", "css");

SSVC.Wrap.Dojo.Require([
    "dojo/_base/fx",
    "dojo/_base/lang",
    "dojo/dom-style",
    "dojo/mouse",
    "dojo/on",
    "dijit/_WidgetBase",
    "dijit/_TemplatedMixin",
    "dojo/text!../scripts/FeedToolbar.html"],

	 SSVC.Wrap.Dojo.Hitch(this,
		function(baseFx, lang, domStyle, mouse, on, _WidgetBase, _TemplatedMixin, template)
		{
			return SSVC.Wrap.Dojo.SetObject("SSVC.UI.FeedToolbar", SSVC.Wrap.Dojo.Declare([_WidgetBase, _TemplatedMixin, SSVC.UI.TemplateControl], {

				DisplayOptions: null,

				constructor: function(displayOptionsArr)
				{
					this.DisplayOptions = displayOptionsArr;
				},

				FeedToolbarInputText: SSVC.Utils.GetResource("feed_tb_def_comment"),
				DisplayModeSelectorLbText: SSVC.Utils.GetResource("feed_tb_display_mode_label"),
				SortingLbText: SSVC.Utils.GetResource("feed_tb_sort_mode_label"),
				FilterInputText: SSVC.Utils.GetResource("feed_tb_def_message_search"),
				MoreOptionsText: SSVC.Utils.GetResource("feed_tb_more_options"),

				// Our template - important!
				templateString: template,

				postCreate: function()
				{
					this.inherited(arguments);

					var options = [
						{ text: SSVC.Utils.GetResource("feed_tb_sm_conversation"), value: SSVC.Utils.Enums.SortMode.Conversation },
						{ text: SSVC.Utils.GetResource("feed_tb_sm_date"), value: SSVC.Utils.Enums.SortMode.Date },
						{ text: SSVC.Utils.GetResource("feed_tb_sm_first_name"), value: SSVC.Utils.Enums.SortMode.FirstName },
						{ text: SSVC.Utils.GetResource("feed_tb_sm_last_name"), value: SSVC.Utils.Enums.SortMode.LastName },
						{ text: SSVC.Utils.GetResource("feed_tb_sm_message"), value: SSVC.Utils.Enums.SortMode.Message },
						{ text: SSVC.Utils.GetResource("feed_tb_sm_file"), value: SSVC.Utils.Enums.SortMode.Date },
						{ text: SSVC.Utils.GetResource("feed_tb_sm_file_page"), value: SSVC.Utils.Enums.SortMode.Date }];
					SSVC.Wrap.Dojo.Array.forEach(options, SSVC.Wrap.Dojo.Hitch(this, function(option)
					{
						var opt = document.createElement("option");
						opt.innerHTML = option.text;
						opt.value = option.value;
						this.ftSortingSelector.appendChild(opt);
					}));

					options = [
						{ text: SSVC.Utils.GetResource("feed_tb_dm_standard"), value: SSVC.Utils.Enums.DisplayMode.Standard },
						{ text: SSVC.Utils.GetResource("feed_tb_dm_review"), value: SSVC.Utils.Enums.DisplayMode.Review }];
					SSVC.Wrap.Dojo.Array.forEach(options, SSVC.Wrap.Dojo.Hitch(this, function(option, i)
					{
						var opt = document.createElement("option");
						opt.innerHTML = option.text;
						opt.value = option.value;
						this.ftDisplayModeSelector.appendChild(opt);
					}));

					this.own(
						on(this.ftTextArea, "focus", lang.hitch(this, "ElementOnFocus", this.ftTextArea, this.FeedToolbarInputText)),
						on(this.ftTextArea, "blur", lang.hitch(this, "ElementOnBlur", this.ftTextArea, this.FeedToolbarInputText)),
						on(this.ftTextArea, "keydown", lang.hitch(this, "TextArea_OnKeyDown", this.ftTextArea)),
						on(this.ftFilterByMessageText, "focus", lang.hitch(this, "ElementOnFocus", this.ftFilterByMessageText, this.FilterInputText)),
						on(this.ftFilterByMessageText, "blur", lang.hitch(this, "ElementOnBlur", this.ftFilterByMessageText, this.FilterInputText)),
						on(this.ftDisplayModeSelector, "change", lang.hitch(this, "DisplayModeSelector_OnChange")),
						on(this.RefreshButtonElement, "click", lang.hitch(this, "RefreshButtonElement_OnClick")),
						on(this.MoreOptionLink, "click", lang.hitch(this, "MoreOptionLink_OnClick")),
						on(this.ftAddCommentBtn, "click", lang.hitch(this, "AddCommentBtn_OnClick")),
						on(this.ftSortingSelector, "change", lang.hitch(this, "SortingSelector_OnChange")),
						on(this.ftFilterFeedButton, "click", lang.hitch(this, "FilterFeedButton_onClick"))
						);
				},

				GetMessageText: function()
				{
					return SSVC.Utils.Page.EncodeHTML(this.ftTextArea.value.trim());
				},

				GetCurrentSortingMode: function()
				{
					return this.ftSortingSelector.options[this.ftSortingSelector.selectedIndex].value;
				},

				GetCurrentDisplayMode: function()
				{
					return this.ftDisplayModeSelector.options[this.ftDisplayModeSelector.selectedIndex].value;
				},

				OnChangeDisplayMode: function(args) { },
				OnChangeSortingMode: function(args) { },
				OnRefreshButtonClick: function(args) { },
				OnMoreOptionLinkClick: function(args) { },
				OnAddCommentBtnClick: function(args) { },
				OnFilterFeedButtonClick: function(args) { },
				OnTextAreaKeyDown: function(event, args) { },

				DisplayModeSelector_OnChange: function() { this.OnChangeDisplayMode(arguments); },
				SortingSelector_OnChange: function() { this.OnChangeSortingMode(arguments); },
				RefreshButtonElement_OnClick: function() { this.OnRefreshButtonClick(arguments); },
				MoreOptionLink_OnClick: function() { this.OnMoreOptionLinkClick(arguments); },
				AddCommentBtn_OnClick: function() { this.OnAddCommentBtnClick(arguments); },
				FilterFeedButton_onClick: function() { this.OnFilterFeedButtonClick(arguments); },
				TextArea_OnKeyDown: function() { this.OnFilterFeedButtonClick(event, arguments); }
			}));
		}));
